﻿using System.Collections.Generic;

namespace EPiMVC.Templates.Web.ViewModels
{
    public class Structure<T>
    {
        private List<Node<T>> nodes = new List<Node<T>>();

        public Node<T> AddNode(T nodeValue)
        {
            Node<T> node = new Node<T>(nodeValue);
            nodes.Add(node);
            node.Parent = this;

            return node;
        }

        public IEnumerable<Node<T>> Nodes
        {
            get { return nodes; }
        }

        public Structure<T> Parent
        {
            get;
            protected internal set;
        }

        public bool HasNodes
        {
            get
            {
                return nodes.Count > 0;
            }
        }

        public void RemoveNode(Node<T> childNode)
        {
            nodes.Remove(childNode);
            childNode.Parent = null;
        }
    }
}